fix: stabilize local dev auth startup#3252
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cd0056b. Configure here.
ApprovabilityVerdict: Needs human review This PR modifies authentication-related code paths including credential submission handling, request proxy routing for auth endpoints, and clerk bridge initialization. Changes to auth flows and security-sensitive code require human review. You can customize Macroscope's approvability policy. Learn more. |
Gate Clerk-dependent renderer and desktop bridge setup when local config is absent, register the desktop schemes independently, proxy custom-scheme requests through the app protocol, and load the diff worker via the portable package worker entry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Route configured loopback HTTP requests through the Vite origin so browser-session cookies are scoped to the page origin, while preserving direct WebSocket targets. Dedupe same-token pairing submits and tolerate stale one-time-token retries when a session is already authenticated. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Stream desktop protocol proxy responses instead of buffering complete bodies, and wait for browser sessions to become observable after manual pairing exchanges. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

What Changed
Why
Local development could fail when Clerk config was missing or when running the web dev flow through
vp run dev. Clerk was being loaded too eagerly, desktop scheme registration depended on Clerk bridge setup, diff worker imports could fail under Vite, and pairing-token exchange could consume a one-time token before the browser session was observable on the correct origin.This keeps local startup resilient without Clerk config, avoids CORS/cookie-origin issues by using the web/Vite origin for browser HTTP requests, and preserves direct loopback WebSockets where required.
UI Changes
Checklist
Note
Medium Risk
Touches auth credential exchange, primary HTTP URL resolution, and the desktop protocol proxy path—areas that affect cookies, pairing, and renderer loading, though changes are guarded by tests and mostly dev-scoped.
Overview
Stabilizes local development when Clerk config is missing or auth runs through Vite/desktop custom schemes.
Desktop: Clerk bridge acquisition is gated on
desktopClerkBridgeEnabled; when disabled, the customt3code/t3code-devscheme is registered up front inmain.tsinstead of relying on Clerk side effects. Protocol proxying moves fromElectron.net.fetchto EffectHttpClient(Undici), with streamed bodies, hop-by-hop header stripping, andregisterDesktopSchemePrivileges.Web primary environment:
resolveHttpRequestBaseUrlroutes loopback HTTP through the Vite dev origin when the page is served from the dev server, and throught3code-dev://appwhen the desktop dev shell is active—keeping cookies/proxy behavior aligned while WebSocket bases stay direct.Auth bootstrap:
submitServerAuthCredentialdedupes concurrent submits for the same token, waits for session observability after exchange, and treats invalid-credential responses as success if the session is already authenticated.Bundling/dev UX: Clerk UI and cloud auth root load via
React.lazy; diff workers use@pierre/diffs/worker/worker-portable.js; Vite definesVITE_DEV_SERVER_URL, tightens HMRclientPort, and drops an unused@pierre/diffsoptimizeDeps entry.Reviewed by Cursor Bugbot for commit 89bf5f5. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix local dev auth startup by stabilizing Clerk bridge initialization and HTTP request routing
DesktopClerk.makeDesktopClerkLayerbehind anenabledflag, skipping bridge setup entirely when no frontend API hostname is configured.target.tsto route loopback requests through the Vite dev server origin or the desktop dev custom scheme (t3code-dev://) as appropriate.Electron.net.fetchinElectronProtocol.tswith an injectedHttpClient(Undici at runtime), adding hop-by-hop header filtering and streaming response bodies without buffering.auth.ts, treating an already-authenticated session as success instead of surfacing an error on race or retry.Macroscope summarized 89bf5f5.